set @start_read_only= @@global.read_only;
set @start_autocommit= @@global.autocommit;
set @@global.autocommit= 0;
SET SESSION lock_wait_timeout=1;
CREATE TABLE t1 ( a INT, b INT) ENGINE=InnoDB;
INSERT INTO t1 VALUES (1, 1);
INSERT INTO t1 VALUES (2, 2);
INSERT INTO t1 VALUES (3, 3);
CREATE TABLE t2 ( a INT) ENGINE=InnoDB;
INSERT INTO t2 VALUES (10);
INSERT INTO t2 VALUES (20);
INSERT INTO t2 VALUES (30);
ALTER TABLE t2 ADD PRIMARY KEY (a);
SET SESSION lock_wait_timeout=1;
SET SESSION innodb_lock_wait_timeout=1;
BEGIN;
LOCK TABLES t2 READ;
BEGIN;
SET SESSION lock_wait_timeout=1;
SET SESSION innodb_lock_wait_timeout=1;
SELECT * FROM t1 FOR UPDATE;
SELECT * FROM t1 FOR UPDATE SKIP LOCKED;
SELECT * FROM t1 FOR SHARE;
SELECT * FROM t1, t2 FOR SHARE OF t1 FOR UPDATE OF t2;
SELECT * FROM t1, t2 FOR SHARE OF t1 FOR SHARE OF t2;
SELECT * FROM t1 FOR SHARE OF t1 NOWAIT;
SELECT * FROM t1 FOR SHARE OF t1 SKIP LOCKED;
SELECT * FROM t1, t2 FOR SHARE OF t1 NOWAIT FOR SHARE OF t2 NOWAIT;
COMMIT;
UNLOCK TABLES;
COMMIT;
BEGIN;
LOCK TABLES t2 WRITE;
BEGIN;
SET SESSION innodb_lock_wait_timeout=1;
SELECT * FROM t1 FOR UPDATE;
SELECT * FROM t1 FOR UPDATE NOWAIT;
SELECT * FROM t1 FOR UPDATE SKIP LOCKED;
SELECT * FROM t1 FOR SHARE;
SELECT * FROM t1 FOR SHARE NOWAIT;
SELECT * FROM t1 FOR SHARE SKIP LOCKED;
SELECT * FROM t1, t2 FOR SHARE OF t1 FOR UPDATE OF t2;
SELECT * FROM t1, t2 FOR SHARE OF t1 FOR SHARE OF t2;
SELECT * FROM t1 FOR SHARE OF t1 NOWAIT;
SELECT * FROM t1 FOR SHARE OF t1 SKIP LOCKED;
SELECT * FROM t1, t2 FOR SHARE OF t1 NOWAIT FOR SHARE OF t2 NOWAIT;
COMMIT;
UNLOCK TABLES;
COMMIT;
DROP TABLE t1, t2;
set @@global.read_only= @start_read_only;
set @@global.autocommit= @start_autocommit;
